package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RecommendUserService {
    @Reference(version="1.0.0")
    private RecommendUserApi recommendUserApi;
    public TodayBest queryTodayBest(Long id) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(id);
        if(recommendUser==null){
            return null;
        }
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        Double score = recommendUser.getScore();
        double ceil = Math.ceil(score);
        todayBest.setFateValue(Double.valueOf(ceil).longValue());
        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {
        PageInfo<RecommendUser> recommendUserPageInfo = recommendUserApi.queryPageInfo(id, page, pagesize);
        return recommendUserPageInfo;
    }

    public Long queryTodayBestValueById(Long toUserId, Long userId) {
        Double value = recommendUserApi.queryById(userId, toUserId);

            double ceil = Math.floor(value);
            return Double.valueOf(ceil).longValue();

    }

    public List<RecommendUser> queryCardList(Long id, int count) {
        return recommendUserApi.queryCardList(id,count);
    }
}
